#ifndef _CGNS_READER_H_


#define _CGNS_READER_H_

#include "grid.h"

namespace util {

template <class itype , class dtype , int dim > 
  void readCGNSGrid( pavan::grid<itype,dtype,dim> &G , const char *file ){

}

template <class itype , class dtype , int dim > 
  void readPlot3DGrid( pavan::grid<itype,dtype,dim> &G , 
                       const char *file , const char *boco_file ){
  std::ifstream fin(file);
  itype nb , ncuts , owner;
  DECL_VEC( itype , dim ) _range;
  pavan::zoneInterface<itype,dtype,dim> tmp_cut;
  if( fin.fail() ) {
    std::cerr << "Error : Opening file " << file << "\n";
    exit(0);
  }
  fin >> nb; // Number of blocks
  G.setNumBlocks( nb );
  for( itype i = 0 ; i < nb ; ++i ) {
    for( int j = 0 ; j < dim ; ++j ) fin >> _range(j);
    G.setBlockExtent( i , _range );
  }

  for( itype ib = 0 ; ib < nb ; ++ib ) {    
    DECL_BZ_VEC( dtype , dim ) &coord = 
      const_cast<DECL_BZ_VEC( dtype , dim ) &>(G.getBlockCoords(ib));
    // 2D grid
    if( dim == 2 )
      DECL_LOOP_2( coord , itype , dim ) 
        fin >> coord[ivar](i,j);
    // 3D grid
    if( dim == 3 )
      DECL_LOOP_3( coord , itype , dim )
        fin >> coord[ivar](i,j,k);
  }

  fin.close();
  fin.open( boco_file );
  if( fin.fail() ) {
    std::cerr << "Error : Opening file " << boco_file << "\n";
    exit(0);
  }
  fin >> ncuts;
  DECL_BLOCK_VEC( itype , dtype , dim ) &blks = 
     const_cast<DECL_BLOCK_VEC( itype , dtype , dim ) &>(G.getAllBlocks());
  for( itype icut = 0 ; icut < ncuts ; ++icut ) {
    fin >> owner ; owner--;
    assert( owner < blks.size() && owner >= 0 );
    for( int id = 0 ; id < dim ; ++id ) 
      fin >> tmp_cut._rangeBegin(id);
    tmp_cut._rangeBegin -= 1;
    for( int id = 0 ; id < dim ; ++id ) 
      fin >> tmp_cut._rangeEnd(id);
    tmp_cut._rangeEnd -= 1;
    fin >> tmp_cut._donorBlockID; tmp_cut._donorBlockID--;
    for( int id = 0 ; id < dim ; ++id )
      fin >> tmp_cut._donorRangeBegin(id);
    tmp_cut._donorRangeBegin -= 1;
    for( int id = 0 ; id < dim ; ++id )
      fin >> tmp_cut._donorRangeEnd(id);
    tmp_cut._donorRangeEnd -= 1;
    for( int id = 0 ; id < dim ; ++id )
      fin >> tmp_cut._transform(id);
    blks[owner].addCutBC( tmp_cut );
  }
}

}
#endif

